home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Sources / FWObjReg.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  4.8 KB  |  161 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWObjReg.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef   FWOBJREG_H
  13. #include "FWObjReg.h"
  14. #endif
  15.  
  16. #ifndef   FWPRIDEB_H
  17. #include "FWPriDeb.h"
  18. #endif
  19.  
  20. #ifndef   FWPRIMEM_H
  21. #include "FWPriMem.h"
  22. #endif
  23.  
  24. #if FW_LIB_EXPORT_PRAGMAS
  25. #pragma lib_export on
  26. #endif
  27.  
  28. #pragma segment FWArchiv
  29.  
  30.  
  31. //========================================================================================
  32. // CLASS FW_CObjectRegistry
  33. //========================================================================================
  34.  
  35. //----------------------------------------------------------------------------------------
  36. //    FW_CObjectRegistry::~FW_CObjectRegistry
  37. //----------------------------------------------------------------------------------------
  38.  
  39. FW_CObjectRegistry::~FW_CObjectRegistry()
  40. {
  41. }
  42.  
  43. //----------------------------------------------------------------------------------------
  44. //    FW_CObjectRegistry::FW_CObjectRegistry
  45. //----------------------------------------------------------------------------------------
  46.  
  47. FW_CObjectRegistry::FW_CObjectRegistry()
  48. {
  49. }
  50.  
  51. //========================================================================================
  52. // CLASS FW_CBasicObjectRegistry
  53. //========================================================================================
  54.  
  55. //----------------------------------------------------------------------------------------
  56. //    FW_CBasicObjectRegistry::~FW_CBasicObjectRegistry
  57. //----------------------------------------------------------------------------------------
  58.  
  59. FW_CBasicObjectRegistry::~FW_CBasicObjectRegistry(void)
  60. {
  61.     FW_PrimitiveFreeBlock(fList);
  62. }
  63.  
  64. //----------------------------------------------------------------------------------------
  65. //    FW_CBasicObjectRegistry::FW_CBasicObjectRegistry
  66. //----------------------------------------------------------------------------------------
  67.  
  68. FW_CBasicObjectRegistry::FW_CBasicObjectRegistry(void) :
  69.     fList(0),
  70.     fListLength(0),
  71.     fPhysicalListLength(0),
  72.     fNextUnusedID(1)
  73. {
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    FW_CBasicObjectRegistry::GrowList
  78. //----------------------------------------------------------------------------------------
  79.  
  80. void FW_CBasicObjectRegistry::GrowList()
  81. {
  82.     long bytesNeeded = (fPhysicalListLength+kExpansion) * sizeof(SAssociation);
  83.     if (fList == 0)
  84.         fList = (SAssociation*) FW_PrimitiveAllocateBlock(bytesNeeded);
  85.     else
  86.         fList = (SAssociation*) FW_PrimitiveResizeBlock(fList, bytesNeeded);
  87.     
  88.     for (long i=fPhysicalListLength; i<fPhysicalListLength+kExpansion; i++)
  89.         InitAssociation(fList[i]);
  90.         
  91.     fPhysicalListLength += kExpansion;
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CBasicObjectRegistry::Register
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CObjectRegistry::ID FW_CBasicObjectRegistry::Register(const void *object)
  99. {
  100.     FW_ASSERT(Lookup(object) == kNotInRegistry);
  101.     if (fListLength == fPhysicalListLength)
  102.         GrowList();
  103.     long entry = fListLength++;
  104.     fList[entry].fObject = object;
  105.     while (Lookup(fNextUnusedID) != 0)
  106.         fNextUnusedID++;
  107.     fList[entry].fID = fNextUnusedID++;
  108.     return fList[entry].fID;
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. //    FW_CBasicObjectRegistry::Register
  113. //----------------------------------------------------------------------------------------
  114.  
  115. void FW_CBasicObjectRegistry::Register(const void *object, FW_CObjectRegistry::ID id)
  116. {
  117.     FW_ASSERT(Lookup(object) == kNotInRegistry);
  118.     FW_ASSERT(Lookup(id) == 0);
  119.     if (fListLength == fPhysicalListLength)
  120.         GrowList();
  121.     long entry = fListLength++;
  122.     fList[entry].fObject = object;
  123.     fList[entry].fID = id;
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    FW_CBasicObjectRegistry::Lookup
  128. //----------------------------------------------------------------------------------------
  129.  
  130. FW_CObjectRegistry::ID FW_CBasicObjectRegistry::Lookup(const void *object)
  131. {
  132.     FW_CObjectRegistry::ID result = kNotInRegistry;
  133.     for (long i = 0; i<fListLength; i++)
  134.     {
  135.         if (fList[i].fObject == object)
  136.         {
  137.             result = fList[i].fID;
  138.             break;
  139.         }
  140.     }
  141.     return result;
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    FW_CBasicObjectRegistry::Lookup
  146. //----------------------------------------------------------------------------------------
  147.  
  148. const void* FW_CBasicObjectRegistry::Lookup(FW_CObjectRegistry::ID id)
  149. {
  150.     const void* result = 0;
  151.     for (long i = 0; i<fListLength; i++)
  152.     {
  153.         if (fList[i].fID == id)
  154.         {
  155.             result = fList[i].fObject;
  156.             break;
  157.         }
  158.     }
  159.     return result;
  160. }
  161.